package com.smartwebee.android.blespp.blockly.command;

public class CommandH5Delegate implements CommandInterface {
    private CommandImpl impl;
    private static CommandH5Delegate delegate;

    private CommandH5Delegate() {
        this.impl = new CommandImpl();
    }

    public static CommandH5Delegate INSTANCE() {
        if (delegate == null) {
            delegate = new CommandH5Delegate();
        }
        return delegate;
    }

    @Override
    public String getLedStr(String index, String red, String green, String blue) {
        String indexTarget = getTargetIndex(index);
        return impl.getLedStr(indexTarget, red, green, blue);
    }


    @Override
    public String getBeepStr(String freq, String rhythm) {
        String targetFreq = getTargetFreq(freq);
        return impl.getBeepStr(targetFreq, rhythm);
    }

    private String getTargetIndex(String index) {
        if (index.equals("全部")) {
            return "3";
        }
        if (index.equals("左")) {
            return "0";
        }
        if (index.equals("右")) {
            return "1";
        }
        return "";
    }

    private String getTargetFreq(String freq) {
        if (freq.equals("C2")) {
            return "65";
        }
        if (freq.equals("D2")) {
            return "73";
        }
        if (freq.equals("E2")) {
            return "82";
        }
        if (freq.equals("F2")) {
            return "87";
        }
        if (freq.equals("G2")) {
            return "97";
        }
        if (freq.equals("A2")) {
            return "110";
        }
        if (freq.equals("B2")) {
            return "123";
        }

        if (freq.equals("C3")) {
            return "130";
        }
        if (freq.equals("D3")) {
            return "146";
        }
        if (freq.equals("E3")) {
            return "164";
        }
        if (freq.equals("F3")) {
            return "174";
        }
        if (freq.equals("G3")) {
            return "195";
        }
        if (freq.equals("A3")) {
            return "220";
        }
        if (freq.equals("B3")) {
            return "246";
        }

        if (freq.equals("C4")) {
            return "261";
        }
        if (freq.equals("D4")) {
            return "293";
        }
        if (freq.equals("E4")) {
            return "329";
        }
        if (freq.equals("F4")) {
            return "349";
        }
        if (freq.equals("G4")) {
            return "391";
        }
        if (freq.equals("A4")) {
            return "440";
        }
        if (freq.equals("B4")) {
            return "493";
        }

        if (freq.equals("C5")) {
            return "523";
        }

        return "";
    }
}
